import { parseId } from "./../utils/index";
import { HCode } from "./code";
import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from "./../constants/index";

export class HResponse<T, R> {
  oid: string;
  code: number;
  message?: string;
  data: T;
  reference?: R;
  st?: number;

  constructor(data: T, reference?: R, code = HCode.success, message: string = 'success') {
    this.data = data;
    this.code = code;
    this.reference = reference;
    this.message = message;
    this.oid = parseId().toString();
    this.st = new Date().getTime();
  }
}

export class Paging {
  ps?: number;  // pageSize 每页条数
  pi?: number;  // pageIndex 第几页，默认为0
  count?: number;
  page_count?: number;
  constructor(ps: number = DEFAULT_PAGE_SIZE, pi: number = DEFAULT_PAGE_INDEX, count?: number, pageCount?: number) {
    this.ps = ps;
    this.pi = pi;
    this.count = count;
    this.page_count = pageCount;
  }
}

export class HPagingResponse<T, R> extends HResponse<T, R> {
  paging?: Paging;
  constructor(data: T, paging?: Paging, reference?: R, code = HCode.success, message: string = 'success' ) {
    super(data, reference, code, message);
    this.paging = paging;
  }
}